﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using Model;

namespace Bussiness
{
    public class ManagerEmploy
    {
        public static bool EmployUserExist(Employ user)
        {
            var q = DataAccessEmploy.GetEmployByIdAndPassword(user);
            if(q.Count!=1)
                return false;
            return true;
        }

        public static void RegisterOrUpdateEmployee(Employ newEmployee)
        {
            if (EmployUserExist(newEmployee))
            {
                newEmployee.BranchId = DataAccessBranch.GetLastBranch().BranchId;
                newEmployee.Branch = null;
                DataAccessEmploy.UpdateEmployee(newEmployee);
            }
            else
            {
                newEmployee.BranchId = DataAccessBranch.GetLastBranch().BranchId;
                newEmployee.Branch = null;
                DataAccessEmploy.InsertEmployee(newEmployee);
            }
        }

        public static List<Employ> GetAllEmploy { get; set; }
    }
}
